Developer Documentation

QuickTime 4 API Documentation

Wired Movies and Sprites

| Previous | Chapter Contents | Chapter Top | Next |

Defining Override Samples

Once you have defined a key frame sample for the sprite track, you can add any number of override samples to modify sprite properties.

Listing 3-11 shows the portion of the AddSpriteTrackToMovie function that adds override samples to the sprite track to make the first penguin sprite appear to waddle and move across the screen. For each override sample, the function modifies the first penguin sprite's image index and location. The function calls SetSpriteData to update the appropriate property atoms in the sprite atom container. Then, the function calls AddSpriteToSample to add the sprite atom container to the sample atom container. After all of the modifications have been made to the override sample, the function calls AddSpriteSampleToMedia to add the override sample to the media.

After adding all of the override samples to the media, AddSpriteTrackToMovie calls EndMediaEdits to indicate that it is done adding samples to the media. Then, AddSpriteTrackToMovie calls InsertMediaIntoTrack to insert the new media segment into the track.

Listing 11 Adding override samples to move penguin one and change its image index

// original penguin one location
    myLocation.h    = (3 * kSpriteTrackWidth / 8) - (kPenguinWidth / 2);
    myLocation.v    = (kSpriteTrackHeight / 4) - (kPenguinHeight / 2);

    myDelta = (kSpriteTrackHeight / 2) / kNumOverrideSamples;
    myIndex = kPenguinDownRightCycleStartIndex;
    
    for (i = 1; i <= kNumOverrideSamples; i++) {
        QTRemoveChildren(mySample, kParentAtomIsContainer);
        QTNewAtomContainer(&myPenguinOneOverride);

        myLocation.h += myDelta;
        myLocation.v += myDelta;
        myIndex++;
        if (myIndex > kPenguinDownRightCycleEndIndex)
            myIndex = kPenguinDownRightCycleStartIndex;
            
        SetSpriteData(myPenguinOneOverride, &myLocation, NULL, NULL,
                        &myIndex, NULL, NULL, NULL);
        AddSpriteToSample(mySample, myPenguinOneOverride,
                            kPenguinOneSpriteID);
        AddSpriteSampleToMedia(myMedia, mySample,
                                kSpriteMediaFrameDuration, false, NULL);                                            
        QTDisposeAtomContainer(myPenguinOneOverride);
    }

    EndMediaEdits(myMedia);
    
    // add the media to the track
    InsertMediaIntoTrack(myTrack, 0, 0, GetMediaDuration(myMedia),
                            fixed1);


© 1999 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |